#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e6 + 10;
struct node{
	int l, r;
}a[N];
int n;

bool cmp(node& a, node& b)
{
	return a.l < b.l;
}

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r;
	
	sort(a + 1, a + 1 + n, cmp);
	int ret = 1, r = a[1].r;
	for(int i = 2; i <= n; i++)
	{
		int l = a[i].l;
		if(l >= r)
		{
			ret++;
			r = a[i].r;
		}
		else
		{
			r = min(r, a[i].r);
		}
	}
	
	cout << ret << endl;
	
	return 0;
} 
